<html>
<head><meta charset="utf-8"><title>specialization &amp; inference · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/specialization.20.26.20inference.html">specialization &amp; inference</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="232724103"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/specialization%20%26%20inference/near/232724103" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/specialization.20.26.20inference.html#232724103">(Apr 01 2021 at 08:56)</a>:</h4>
<p>How does specialization currently interact with inference? Not knowing much about the internals of inference, it <em>feels</em> like only the generic impl need be taken into account, as the specialized impls are inherently subsumed by it type-wise (the resolver should handle it, not inference, is my thought).</p>
<p>I ask because I was trying to make a change to a stdlib type, but would need specialization to avoid a significant regression in runtime performance among existing code. Unfortunately, the inference fails when I add the specialization, which I believe to be a case of <a href="https://github.com/rust-lang/rust/issues/46363">rust-lang/rust#46363</a>. If the specialized impls functionally ignored for inference purposes, this issue wouldn't exist…I think.</p>



<a name="232724502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/specialization%20%26%20inference/near/232724502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/specialization.20.26.20inference.html#232724502">(Apr 01 2021 at 09:00)</a>:</h4>
<p>Looks like I'm not the first one to expect specialization to not affect inference either: <a href="https://github.com/rust-lang/rust/issues/36262">rust-lang/rust#36262</a></p>



<a name="232724506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/specialization%20%26%20inference/near/232724506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/specialization.20.26.20inference.html#232724506">(Apr 01 2021 at 09:00)</a>:</h4>
<p>Specialized impls are not ignored for inference (the same code is used for both inference and codegen).</p>



<a name="232724926"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/specialization%20%26%20inference/near/232724926" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/specialization.20.26.20inference.html#232724926">(Apr 01 2021 at 09:04)</a>:</h4>
<p>Is there any way to work around this? I suspect not, but you never know. The code I was trying to write is functionally identical to the first example in <a href="https://github.com/rust-lang/rust/issues/36262">#36262</a></p>



<a name="232724991"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/specialization%20%26%20inference/near/232724991" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/specialization.20.26.20inference.html#232724991">(Apr 01 2021 at 09:04)</a>:</h4>
<p>I didn't realize that the same code was used for inference and codegen, though. That would certainly explain things to an extent.</p>



<a name="232725010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/specialization%20%26%20inference/near/232725010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/specialization.20.26.20inference.html#232725010">(Apr 01 2021 at 09:04)</a>:</h4>
<p>Use a private trait for specialization?</p>



<a name="232725062"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/specialization%20%26%20inference/near/232725062" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/specialization.20.26.20inference.html#232725062">(Apr 01 2021 at 09:05)</a>:</h4>
<p>And then fully qualify the paths.</p>



<a name="232725134"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/specialization%20%26%20inference/near/232725134" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/specialization.20.26.20inference.html#232725134">(Apr 01 2021 at 09:06)</a>:</h4>
<p>As in create an identical trait locally, then just delegate the methods in the public trait?</p>



<a name="232725358"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/specialization%20%26%20inference/near/232725358" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/specialization.20.26.20inference.html#232725358">(Apr 01 2021 at 09:07)</a>:</h4>
<p><a href="https://github.com/rust-lang/std-dev-guide/blob/master/src/code-considerations/using-unstable-lang/specialization.md">https://github.com/rust-lang/std-dev-guide/blob/master/src/code-considerations/using-unstable-lang/specialization.md</a></p>



<a name="232725515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/specialization%20%26%20inference/near/232725515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Pratt <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/specialization.20.26.20inference.html#232725515">(Apr 01 2021 at 09:08)</a>:</h4>
<p>So basically! I'll give it a shot. Thanks for the info!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>